﻿create procedure dbo.GetMyTakeoutProviders

	(
		@UserID int,
		@RetentionTime int
	)

AS


SELECT     dbo.TakeoutProvider.Id, dbo.TakeoutProvider.MenuID, dbo.TakeoutProvider.PaymentSourceID, dbo.TakeoutProvider.UserID, dbo.Menus.Name AS MenuName, 
                      dbo.PaymentSource.Name AS PaymentSourceName, dbo.TakeoutProvider.ExpirationTime, dbo.TakeoutProvider.StartTime, dbo.TakeoutProvider.MaximumOrders, 
                      dbo.TakeoutProvider.TakeoutCharge, dbo.TakeoutProvider.Instructions, dbo.TakeoutProvider.AllowPayMeLater, DATEDIFF(minute, GETDATE(), 
                      dbo.TakeoutProvider.ExpirationTime) AS MinutesRemaining
FROM         dbo.TakeoutProvider INNER JOIN
                      dbo.Menus ON dbo.TakeoutProvider.MenuID = dbo.Menus.Id INNER JOIN
                      dbo.PaymentSource ON dbo.TakeoutProvider.PaymentSourceID = dbo.PaymentSource.Id
WHERE     (dbo.TakeoutProvider.UserID = @UserID) AND (DATEDIFF(minute, GETDATE(), dbo.TakeoutProvider.ExpirationTime) >= @RetentionTime)

	RETURN


